﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TournamentOrganizerWPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        Tournament tournament;

        public MainWindow()
        {
            InitializeComponent();
            tournament = Tournament.Instance;
            this.DataContext = tournament;

            tournament.AddPlayer(new Player(1, "Testperson1", "Default location"));
            tournament.AddPlayer(new Player(2, "Testperson2", "Default location"));
        }

        public MainWindow(Tournament tournament)
        {
            InitializeComponent();
            this.tournament = tournament;
            this.DataContext = tournament;
        }

        private void AddPlayer(object sender, RoutedEventArgs e)
        {
            string roundNoString = "";
            roundNoString = roundNo.Content.ToString();

            if (roundNoString == "0")
            {
                var addPlayer = new AddPlayerWindow(tournament);
                addPlayer.Show();
            }           
        }

        private void MatchNextRound(object sender, RoutedEventArgs e)
        {
            tournament.MatchNextRound();

            playerGrid.Items.Refresh();

            roundNo.Content = tournament.RoundNo;
        }

        private void AddLocations(object sender, RoutedEventArgs e)
        {
            var addLocationWindow = new AddLocationWindow(tournament);
            addLocationWindow.Show();
        }

        private void RemovePlayer(object sender, RoutedEventArgs e)
        {
            var removePlayerWindow = new RemovePlayerWindow(tournament);
            removePlayerWindow.Show();
        }


        private void PrintMatches(object sender, RoutedEventArgs e)
        {
            tournament.PrintMatches();
        }

        private void PrintStandings(object sender, RoutedEventArgs e)
        {
            tournament.PrintStandings();
        }

        private void SaveTournament(object sender, RoutedEventArgs e)
        {
           LoadSave.SaveTournament(tournament);
        }

        private void LoadTournament(object sender, RoutedEventArgs e)
        {
            tournament = LoadSave.LoadTournament();
            playerGrid.UpdateLayout();
            this.DataContext = tournament;
        }

        private void AddAndCheckScenarios(object sender, RoutedEventArgs e)
        {
            var scenarios = new ScenarioOverview(tournament);
            scenarios.Show();
        }
    }
}
